﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace DisplayBoardInfo.Server.Forms.Board
{
    /// <summary>
    /// Interaction logic for Clock.xaml
    /// </summary>
    public partial class Clock : UserControl
    {
        //Timer to change clock
        private DispatcherTimer timer;

        public Clock()
        {
            InitializeComponent();

            DateTime now = DateTime.Now;
            date.Content = Helpers.Convert.NumbersToString(now.Day) + "." + Helpers.Convert.NumbersToString(now.Month) + "." + Helpers.Convert.NumbersToString(now.Year);
            hour.Content = Helpers.Convert.NumbersToString(now.Hour);
            minutes.Content = Helpers.Convert.NumbersToString(now.Minute);
            dayOfWeek.Content = Helpers.Convert.GetDayOfWeek(now.DayOfWeek).ToUpper();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(timer_Tick);

            timer.Start();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            colon.Visibility = colon.Visibility == System.Windows.Visibility.Hidden ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
            DateTime now = DateTime.Now;
            hour.Content = Helpers.Convert.NumbersToString(now.Hour);
            minutes.Content = Helpers.Convert.NumbersToString(now.Minute);
            date.Content = Helpers.Convert.NumbersToString(now.Day) + "." + Helpers.Convert.NumbersToString(now.Month) + "." + Helpers.Convert.NumbersToString(now.Year);
            dayOfWeek.Content = Helpers.Convert.GetDayOfWeek(now.DayOfWeek).ToUpper();
        }
    }
}
